package com.ruoyi.web.controller.system;

import java.util.Date;
import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.system.domain.HotelRoom;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.DutyBill;
import com.ruoyi.system.service.IDutyBillService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 值班账单Controller
 * 
 * @author txy
 * @date 2022-02-10
 */
@RestController
@RequestMapping("/system/bill")
public class DutyBillController extends BaseController
{
    @Autowired
    private IDutyBillService dutyBillService;

    /**
     * 查询全部值班账单列表
     */
    @PreAuthorize("@ss.hasPermi('system:bill:query')")
    @GetMapping("/all")
    public AjaxResult all(HotelRoom hotelRoom)
    {
        List<HotelRoom> list = dutyBillService.selectDutyBillListAll(hotelRoom);
        return AjaxResult.success(list);
    }

    /**
     * 查询值班账单列表
     */
    @PreAuthorize("@ss.hasPermi('system:bill:list')")
    @GetMapping("/list")
    public TableDataInfo list(DutyBill dutyBill)
    {
        startPage();
        List<DutyBill> list = dutyBillService.selectDutyBillList(dutyBill);
        return getDataTable(list);
    }

    /**
     * 导出值班账单列表
     */
    @PreAuthorize("@ss.hasPermi('system:bill:export')")
    @Log(title = "值班账单", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, DutyBill dutyBill)
    {
        List<DutyBill> list = dutyBillService.selectDutyBillList(dutyBill);
        ExcelUtil<DutyBill> util = new ExcelUtil<DutyBill>(DutyBill.class);
        util.exportExcel(response, list, "值班账单数据");
    }

    /**
     * 获取值班账单详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:bill:query')")
    @GetMapping(value = "/{billId}")
    public AjaxResult getInfo(@PathVariable("billId") String billId)
    {
        return AjaxResult.success(dutyBillService.selectDutyBillByBillId(billId));
    }

    /**
     * 新增值班账单
     */
    @PreAuthorize("@ss.hasPermi('system:bill:add')")
    @Log(title = "值班账单", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody DutyBill dutyBill)
    {
        dutyBill.setBillStartTime(new Date());
        return toAjax(dutyBillService.insertDutyBill(dutyBill));
    }

    /**
     * 修改值班账单
     */
    @PreAuthorize("@ss.hasPermi('system:bill:edit')")
    @Log(title = "值班账单", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody DutyBill dutyBill)
    {
        dutyBill.setBillEndTime(new Date());
        return toAjax(dutyBillService.updateDutyBill(dutyBill));
    }

    /**
     * 删除值班账单
     */
    @PreAuthorize("@ss.hasPermi('system:bill:remove')")
    @Log(title = "值班账单", businessType = BusinessType.DELETE)
	@DeleteMapping("/{billIds}")
    public AjaxResult remove(@PathVariable String[] billIds)
    {
        return toAjax(dutyBillService.deleteDutyBillByBillIds(billIds));
    }
}
